<?php
namespace app\home\model;

use think\Db;

class RecordModel
{
    /**
     * 单例模式
     * @return BannerModel
     *
     */
    public static function instance()
    {
        static $m = null;
        if (!$m) {
            $m = new RecordModel();
        }
        return $m;
    }

    public function recordlist($bid, $field)
    {
        $num = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->count();
        $money = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->sum('money');
        $list = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->field($field)->order('paytime desc')->paginate(10);
        return [$list,$num,$money];
    }
    /**
     * 交易记录
     */
    public function recordfind($time,$bid){

        $field = 'orderid,order_no,money,paytime';
        if(strlen($time)<12){
            $num = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($time))->where('paytime','<',(strtotime($time)+24*60*60))->count();
            $money = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($time))->where('paytime','<',(strtotime($time)+24*60*60))->sum('money');
            $list = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($time))->where('paytime','<',(strtotime($time)+24*60*60))->field($field)->order('paytime desc')->paginate(1000);
            return [$list,$num,$money];
        }else{
            $data = explode('至',$time);
            $num = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($data[0]))->where('paytime','<',(strtotime($data[1])+24*60*60))->count();
            $money = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($data[0]))->where('paytime','<',(strtotime($data[1])+24*60*60))->sum('money');
            $list = Db::name('goods_order')->where('bid', $bid)->where('status','neq','1')->where('paytime','>',strtotime($data[0]))->where('paytime','<',(strtotime($data[1])+24*60*60))->field($field)->order('paytime desc')->paginate(1000);
            return [$list,$num,$money];
        }
    }
}